<?php
//引入初始化文件
include '../init.php';
//引入数据库连接文件
include DIR_CORE .'mysql.php';
//接受数据
$user = trim($_POST['name']);
$password = trim($_POST['password']);
$repassword = trim($_POST['repassword']);
$time = time();
//var_dump($_POST);
//die;
//判断数据合法性
if (empty($user)||empty($password)) {
    jump('../view/regist.html', '用户名和密码不能为空！');
}
if ($password!=$repassword) {
    jump('../view/regist.html', '两次密码不一致');
}
if (strlen($password)<4 || strlen($password)>12) {
    jump('../view/regist.html', '密码必须在4-12之间');
}
if (strlen($user)<4 || strlen($user)>16) {
    jump('../view/regist.html', '用户名必须在4-16之间');
}
//判断用户名是否存在
$m_password = md5($password);
$sql="select * from user where name= '$user'";
$res = mysqli_query($link, $sql);
if (mysqli_affected_rows($link, )>0) {
    jump('../view/regist.html', '用户名已存在！');
}
//数据入库
$sql = "insert into user (`name`,`password`,`created_time`)values('$user','$m_password','$time')";

$res = mysqli_query($link, $sql);
if ($res) {
    jump('../view/login.html', '注册成功！');
} else {
    jump('../view/regist.html', '注册失败！');
}
